<template>
    <div class="banner-container">
        <swiper class="home-swiper" :options="swiperOption" ref="mySwiper" v-if="showSwiper">
            <!-- slides -->
            <swiper-slide v-for="item of swiperList" :key="item.id">
                <img class="swiper-img" :src="item.imgUrl" alt="">
            </swiper-slide>
            <!-- Optional controls -->
            <div class="swiper-pagination"  slot="pagination"></div>
        </swiper>
    </div>
</template>

<script>
export default {
  name: "carrousel",
  props:{
     swiperList:Array
  },
  data() {
    return {
      swiperOption: {
          pagination:'.swiper-pagination',
          loop:true,
          autoplay:3000
        // some swiper options/callbacks
        // 所有的参数同 swiper 官方 api 参数
        // ...
      }
    };
  },
  computed: {
    swiper() {
      return this.$refs.mySwiper.swiper;
    },
    showSwiper(){
      return this.swiperList.length;
    }
  },
  mounted() {
    // current swiper instance
    // 然后你就可以使用当前上下文内的swiper对象去做你想做的事了
    //   this.swiper.slideTo(3, 1000, false)
  }
};
</script>
<style lang="scss" scoped>

.banner-container {
  width: 100%;
  padding-bottom: 30%;
  overflow: hidden;
  height: 0;
  background: #aaa;
  .swiper-img{
    width: 100%;
  }
}
</style>
